﻿using System;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace Data.MappingClasses
{
    [TableAttribute(Name = "dbo.Week")]
    public partial class Week : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private short _idDay;

        private string _nameDay;

        private EntitySet<Lesson> _Lessons;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnidDayChanging(short value);
        partial void OnidDayChanged();
        partial void OnnameDayChanging(string value);
        partial void OnnameDayChanged();
        #endregion

        public Week()
        {
            this._Lessons = new EntitySet<Lesson>(new Action<Lesson>(this.AttachLessons), new Action<Lesson>(this.DetachLessons));
            OnCreated();
        }

        [ColumnAttribute(Storage = "_idDay", AutoSync = AutoSync.OnInsert, DbType = "SmallInt NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public short idDay
        {
            get
            {
                return this._idDay;
            }
            set
            {
                if ((this._idDay != value))
                {
                    this.OnidDayChanging(value);
                    this.SendPropertyChanging();
                    this._idDay = value;
                    this.SendPropertyChanged("idDay");
                    this.OnidDayChanged();
                }
            }
        }

        [ColumnAttribute(Storage = "_nameDay", DbType = "VarChar(15) NOT NULL", CanBeNull = false)]
        public string nameDay
        {
            get
            {
                return this._nameDay;
            }
            set
            {
                if ((this._nameDay != value))
                {
                    this.OnnameDayChanging(value);
                    this.SendPropertyChanging();
                    this._nameDay = value;
                    this.SendPropertyChanged("nameDay");
                    this.OnnameDayChanged();
                }
            }
        }

        [AssociationAttribute(Name = "Week_Lesson", Storage = "_Lessons", ThisKey = "idDay", OtherKey = "refWeek")]
        public EntitySet<Lesson> Lessons
        {
            get
            {
                return this._Lessons;
            }
            set
            {
                this._Lessons.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void AttachLessons(Lesson entity)
        {
            this.SendPropertyChanging();
            entity.Week = this;
        }

        private void DetachLessons(Lesson entity)
        {
            this.SendPropertyChanging();
            entity.Week = null;
        }
    }
}